const applyMysql = require('./tools/applyMysql');
const Socket = require('./tcp/socket');
const TcpManager = require('./tcp/TcpManager');

const Http = require('./http/http');
const HttpManager = require('./http/HttpManager');
const os = require('os');

const fs = require('fs');
const ini = require('ini');
async function init() {
    let mysqlInstance = new applyMysql();
    let socket = new Socket();
    let http = new Http();
    let tcpManager = new TcpManager();
    let httpManager = new HttpManager();

    let file = await giveFileName();
    let ini = await readIni(file);
    

    global.instance = {
        dbHandler : mysqlInstance,
        socketHandler : socket,
        httpHandler : http,
        tcpHandler : tcpManager,
        httpHandler : httpManager,
        ini:ini,
        fileName:file,
    };
    socket.init("127.0.0.1","13002");
    http.start();
}

async function main() {
    init();



}


async function giveFileName() {
    let type = os.platform();
    console.log('type = ',type);
    let fileName;
    if(type == "darwin")
    {
        fileName = "./run.ini";

    }
    else if(type == "win32")
    {
        fileName = "E:/gitee/QtTcpFrameWork/NodeFramework/run.ini";

    }
    else
    {
        fileName = "./run.ini"

    }
    return fileName;
}


async function readIni(fileName) {
    let file = fs.readFileSync(fileName);
    var Info = ini.parse(file.toString());
    return Info;
}



main();